package ch.upndown.upndown;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import ch.upndown.upndown.database.DatabaseAccess;
import ch.upndown.upndown.model.Website;


/**
 *
 * @author Bernard Jaquet
 * @version 0.1
 */
public class DetailFragment extends Fragment {
    private static final String ACTIVE_WEBSITE = "active_website";
    private int activeWebsiteId;
    private DatabaseAccess myDb;

    public DetailFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myDb = DatabaseAccess.getInstance(getActivity());
        if (getArguments() != null) {
            activeWebsiteId = Integer.valueOf(getArguments().getString(ACTIVE_WEBSITE));
        }
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_detail, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        loadWebsite(activeWebsiteId);
    }

    public void loadWebsite(int websiteId) {
        View view = getView();
        if (view == null)
            return;
        if(activeWebsiteId == 0) {
            view.findViewById(R.id.fragment_detail_entry).setVisibility(View.GONE);
            view.findViewById(R.id.fragment_detail_entry).setVisibility(View.VISIBLE);
            return;
        }
        view.findViewById(R.id.fragment_detail_entry).setVisibility(View.VISIBLE);
        view.findViewById(R.id.fragment_detail_entry).setVisibility(View.GONE);
        Website website = myDb.getWebsiteById(activeWebsiteId);
    }

}
